<?php
	session_start();
	/**
	* @package admin
	* @desc This php file is used to find registered admin/users inside the database.
	*/
	// Direct calling check
	if(!isset($_SESSION["role"]))
	{
		header('Location: ../index.php');
		exit();
	}
	if ($_SESSION["role"] != "admin")
	{
		header('Location: ../index.php');
		exit();
	}
	
	/**
	* @desc This include file will load the directory settings for the Smarty Templates
	*/
	require '../includes/smarty.inc';
	$smarty->assign('title', "Add Park");
	$smarty->assign('user_id', $_SESSION["user_id"]);	
	$smarty->assign('last', $_SESSION["lastviewed"]);
	$smarty->assign('firstname', $_SESSION["firstname"]);
	$smarty->assign('role', $_SESSION["role"]);
	$smarty->assign('top5', $_SESSION["top5"]);	
	$smarty->assign('pathdepth', "../");
	$smarty->display('header.tpl');
	
	/**
	* @desc This include file connects to the database.
	*/
	require '../includes/connect.inc';
	
	
	
	$query = "SELECT DISTINCT(role) as role FROM users";
						
	if (!$result = mysql_query ($query, $connection))
		$smarty->assign('fail', 'Failed to load roles');
	else						
	{
		$options = array();
		//Iterate through results, extracting roles		
		while($row = mysql_fetch_row($result))
			$options[] = $row[0];
		$smarty->assign('options', $options);
	}
	
	$smarty->assign('admin', $_SESSION["firstname"]);
	$smarty->display('admin/findusers.tpl');
	
	//Disconnect
	mysql_close($connection);
	
	unset($_SESSION["errors"]);
	unset($_SESSION["form"]);
	
	$smarty->assign('pathdepth', "../");
	$smarty->display('footer.tpl');
		
?>